package com.ev.scm.service.impl;

import com.ev.framework.utils.R;
import com.ev.scm.dao.StockAgeSettingDao;
import com.ev.scm.domain.StockAgeSettingDO;
import com.ev.scm.service.StockAgeSettingService;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service
public class StockAgeSettingServiceImpl implements StockAgeSettingService {
    @Autowired
    private StockAgeSettingDao stockAgeSettingDao;

    @Override
    public StockAgeSettingDO get(Long id) {
        return stockAgeSettingDao.get(id);
    }

    @Override
    public List<StockAgeSettingDO> list(Map<String, Object> map) {
        return stockAgeSettingDao.list(map);
    }

    @Override
    public int count(Map<String, Object> map) {
        return stockAgeSettingDao.count(map);
    }

    @Override
    public int save(StockAgeSettingDO stockAgeSetting) {
        return stockAgeSettingDao.save(stockAgeSetting);
    }

    @Override
    public int update(StockAgeSettingDO stockAgeSetting) {
        return stockAgeSettingDao.update(stockAgeSetting);
    }

    @Override
    public int updateAll(StockAgeSettingDO stockAgeSetting) {
        return stockAgeSettingDao.updateAll(stockAgeSetting);
    }

    @Override
    public int remove(Long id) {
        return stockAgeSettingDao.remove(id);
    }

    @Override
    public int removeAll() {
        return stockAgeSettingDao.removeAll();
    }

    @Override
    public int batchRemove(Long[] ids) {
        return stockAgeSettingDao.batchRemove(ids);
    }

    @Override
    public R saveAndVerify(List<StockAgeSettingDO> stockAgeSettingDOList) {
        this.removeAll();

        List<StockAgeSettingDO> collect = stockAgeSettingDOList.stream().filter(e -> e.getDay() != null && e.getName() != null)
                .collect(Collectors.toList());
        if (collect.size() > 0) {
            stockAgeSettingDao.batchSave(stockAgeSettingDOList);
        }
        return R.ok();
    }

    @Override
    public Map<String, Object> getById(Long id) {
        StockAgeSettingDO stockAgeSetting = stockAgeSettingDao.get(id);
        Map<String, Object> result = Maps.newHashMap();
        if (stockAgeSetting !=null){
            result.put("data",stockAgeSetting);
            return result;
        }
        return result;
    }

    @Override
    public Map<String, Object> pageList() {
        Map<String, Object> result = Maps.newHashMap();
        List<StockAgeSettingDO> list = this.list(Maps.newHashMap());
        if (list.size() > 0) {
            result.put("data", list);
        }
        return result;
    }

}
